﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using ProductIntory.Domains;
using ProductIntory.ErrorCodes;
using ProductIntory.Infrastructures.Interface;
using ProductIntory.Read.Apis.Application.Command.ProductInspectionCommands;
using System.Diagnostics;

namespace ProductIntory.Read.Apis.Application.CommandHandler.ProductInspectionCommandHandlers
{
    public class FirstProductInspectionCommandsHandler : IRequestHandler<FirstProductInspectionCommands, ApiResult<List<ProductInspection>>>
    {
        IBaseRepository<ProductInspection> ProductInspection;

        public FirstProductInspectionCommandsHandler(IBaseRepository<ProductInspection> ProductInspection)
        {
            this.ProductInspection = ProductInspection;
        }

        public async Task<ApiResult<List<ProductInspection>>> Handle(FirstProductInspectionCommands request, CancellationToken cancellationToken)
        {
            var list =await ProductInspection.GetAll().Where(c=>c.ProductsInspection_Id==request.id).ToListAsync();
            if (list != null)
            {
                return new ApiResult<List<ProductInspection>> 
                {
                    Code=ApiEnum.success,
                    Message="反填成功",
                    Data=list
                };
            }
            else 
            {
                return new ApiResult<List<ProductInspection>>
                {
                    Code = ApiEnum.success,
                    Message = "未找到",
                    Data = null
                };
            }
        }
    }
}
